package unclassified.simple;

import java.util.Arrays;
import java.util.Stack;

public class LongestHarmoniousSubsequence_594 {

    public int findLHS(int[] nums) {
        Arrays.sort(nums);
        int ans = 0;
        for (int i = 0, j = 0; j < nums.length; j++) {
            while(i < j && nums[j] - nums[i] > 1) { i++; }
            if (nums[j] - nums[i] == 1) {
                ans = Math.max(ans, j - i + 1);
            }
        }
        return ans;
    }
}
